<?php

$valid_test = Array(
    "select asd,asd FROM table WHERE id > 1",
    "SELECT * FROM",
    "select  asd, asd    FROM ",
  );

$pattern = "/(SELECT|select)[ ]+"
  . "([*]|([A-Za-z0-9_],? ?)+)[ ]+"
  . "(FROM|from)[ ]+"
  . "([A-Za-z0-9_])+[ ]+$?"
  . "(WHERE|where)[ ]+"
  . "/";
//"/SELECT|select [ ]+[*]|([A-Za-z0-9_],?)+ [ ]+FROM/";

foreach ($valid_test as $test) {
  echo preg_match($pattern, $test)."<br>";
}
